{% extends "dashboard/base.html" %}
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}

{% block title %}
  {% trans "Vouchers" context "Dashboard vouchers list" %} - {{ block.super }}
{% endblock %}

{% block body_class %}body-vouchers{% endblock %}

{% block menu_vouchers_class %}active{% endblock %}

{% block breadcrumbs %}
  <ul class="breadcrumbs">
    <li class="visible-s">
      {% trans "Vouchers" context "Dashboard vouchers list" %}
    </li>
  </ul>
{% endblock %}

{% block menu_discounts_class %} active{% endblock %}

{% block content %}
  <div class="card">
    <div class="data-table-header-action">
      <a href="{% url 'dashboard:voucher-add' %}" class="btn-data-table btn-flat" title="{% trans "Add voucher" context "Voucher list add button text" %}">
        {% trans "Add" context "Dashboard add action" %}
      </a>
    </div>
    <div class="data-table-container">
      <table class="bordered highlight responsive data-table">
        {% if vouchers %}
          <thead>
            <tr>
              <th class="wide">
                {% trans "Name" context "Voucher table header" %}
              </th>
              <th class="right-align">
                {% trans "Discount" context "Voucher table header" %}
              </th>
              <th>
                {% trans "Apply to" context "Voucher table header" %}
              </th>
              <th>
                {% trans "Start date" context "Voucher table header" %}
              </th>
              <th>
                {% trans "End date" context "Voucher table header" %}
              </th>
              <th class="right-align">
                {% trans "Used" context "Voucher table header" %}
              </th>
              <th class="right-align">
                {% trans "Limit" context "Voucher table header" %}
              </th>
            </tr>
          </thead>
          {% for voucher in vouchers %}
            <tbody>
              <tr data-action-go="{% url 'dashboard:voucher-update' pk=voucher.pk %}">
                <td>
                  {{ voucher }}
                </td>
                <td class="right-align">
                  {{ voucher.discount_value }}&nbsp;<span class="currency">{{ voucher.get_discount_value_type_display }}</span>
                </td>
                <td>
                  {{ voucher.get_apply_to_display|default_if_none:"-" }}
                </td>
                <td>
                  {{ voucher.start_date }}
                </td>
                <td>
                  {{ voucher.end_date|default_if_none:"-" }}
                </td>
                <td class="right-align">
                  {% if voucher.usage_limit or voucher.usage_limit == 0 %}
                    {{ voucher.used }}/{{ voucher.usage_limit }}
                  {% else %}
                    {{ voucher.used }}
                  {% endif %}
                </td>
                <td class="right-align">
                  {% if voucher.limit %}
                    {% gross voucher.limit html=True %}
                  {% else %}
                    -
                  {% endif %}
                </td>
              </tr>
            </tbody>
          {% endfor %}
        {% else %}
          <tbody>
            <tr>
              <td>
                <span>
                  {% trans "No vouchers found" context "Empty vouchers table message" %}
                </span>
              </td>
            </tr>
          </tbody>
        {% endif %}
      </table>
    </div>
  </div>
  {% include "dashboard/includes/_pagination.html" %}
{% endblock %}
